home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include "scrollmon.h"
-
- Widget glw, toplevel, gfxShell, mainw, frame, menuBar, mainCtrl, speedSb;
- Widget btn, chBoxes, rch, rcv, textF, textFrc, stopStartBtn, pulldownMenu;
- Widget dialog, restartBtn;
- XtAppContext app_context;
- struct resources appResources;
- char *defaultCredFile = "credits.txt";
- extern Boolean credMotion;
- extern Boolean videoBg;
- extern Boolean restart;
- extern long bgcol;
- extern char *gosign[], *stopsign[], *restsign[], *stopmask_bits[];
- Pixmap stopPixmap, goPixmap, restartPixmap;
- Pixmap stopShapemask, goShapemask, restartShapemask;
- XpmAttributes attr;
-
-
- #define offset(field) XtOffsetOf(struct resources, field)
- static XtResource Resources[] = {
- {"perf", "perf", XtRBoolean, sizeof(Boolean),
- offset(perf), XtRString, "False"},
- {"debug", "debug", XtRBoolean, sizeof(Boolean),
- offset(debug), XtRString, "False"},
- {"width", "width", XtRInt, sizeof(int),
- offset(winW), XtRImmediate, (XtPointer)640},
- {"height", "height", XtRInt, sizeof(int),
- offset(winH), XtRImmediate, (XtPointer)480},
- {"speed", "speed", XtRInt, sizeof(int),
- offset(speed), XtRImmediate, (XtPointer)1},
- {"help", "help", XtRBoolean, sizeof(Boolean),
- offset(help), XtRString, "False"},
- {"fps", "fps", XtRInt, sizeof(int),
- offset(fps), XtRImmediate, (XtPointer)60}
- };
- #undef offset
-
- static XrmOptionDescRec optionDesc[] = {
- { "-perf", "perf", XrmoptionNoArg, (caddr_t) "True" },
- { "-debug", "debug", XrmoptionNoArg, (caddr_t) "True" },
- { "-speed", "speed", XrmoptionSepArg, NULL },
- { "-width", "width", XrmoptionSepArg, NULL },
- { "-height", "height", XrmoptionSepArg, NULL },
- { "-help", "help", XrmoptionNoArg, (caddr_t) "True" },
- { "-fps", "fps", XrmoptionSepArg, NULL }
- };
-
- static String fallback_resources[] = {
- // "*stopStartBtn*labelPixmap: stop.xbm",
- "*quitBtn*labelString: Quit",
- "*frame*shadowType: SHADOW_IN",
- "*sgiMode: True",
- NULL
- };
-
- static GLXconfig glxConfig [] = {
- { GLX_NORMAL, GLX_DOUBLE, TRUE },
- { GLX_NORMAL, GLX_RGB, TRUE },
- { GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG },
- { 0, 0, 0 }
- };
-
-
- void fileCB(Widget, int);
-
- extern void readCreditsFile();
- extern void grabTextBlocks(Widget, XtPointer , XtPointer);
-
- /* Process all Input callbacks*/
- static void
- quitCB(Widget, XtPointer, XtPointer)
- {
- exit(0);
- }
-
-
- static void
- toggleMotionCB(Widget, XtPointer, XtPointer)
- {
- Arg args[5];
- int n ;
-
- if (credMotion) {
- credMotion = False;
- n = 0;
- XtSetArg(args[n], XmNlabelPixmap, stopPixmap); n++;
- XtSetValues(stopStartBtn, args, n);
- }
- else {
- credMotion = True;
- n = 0;
- XtSetArg(args[n], XmNlabelPixmap, goPixmap); n++;
- XtSetValues(stopStartBtn, args, n);
- }
- }
-
-
- static void
- updateSpeedCB(Widget w, XtPointer, XtPointer)
- {
- Arg args[5];
- int n ;
-
- n = 0;
- XtSetArg (args[n], XmNvalue, &appResources.speed); n++;
- XtGetValues (w, args, n);
- if (appResources.speed)
- cout << "projected time to scroll: " << (CredSection::totalCredHeight +
- appResources.winH) / (appResources.fps * appResources.speed) << " secs"
- << endl;
- }
-
-
- void
- setPixmaps()
- {
- Arg args[5];
- int n;
- int error = 0;
- int depth = DefaultDepth(XtDisplay(toplevel),
- DefaultScreen(XtDisplay(toplevel)));
-
- XpmCreatePixmapFromData(XtDisplay(toplevel), XtWindow(toplevel),
- stopsign, &stopPixmap, &stopShapemask, &attr);
- if (error)
- cout << "error creating pixmap" << endl;
-
- XpmCreatePixmapFromData(XtDisplay(toplevel), XtWindow(toplevel),
- gosign, &goPixmap, &goShapemask, &attr);
- if (error)
- cout << "error creating pixmap" << endl;
-
- XpmCreatePixmapFromData(XtDisplay(toplevel), XtWindow(toplevel),
- restsign, &restartPixmap, &restartShapemask, &attr);
- if (error)
- cout << "error creating pixmap" << endl;
-
- n = 0;
- XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
- XtSetArg(args[n], XmNlabelPixmap, goPixmap); n++;
- XtSetValues(stopStartBtn, args, n);
-
- n = 0;
- XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
- XtSetArg(args[n], XmNlabelPixmap, restartPixmap); n++;
- XtSetValues(restartBtn, args, n);
- }
-
-
- static void
- installColormap(Widget toplevel, Widget glw)
- {
- Window windows[2];
- int status;
-
- windows[0] = XtWindow(glw);
- windows[1] = XtWindow(toplevel);
- status = XSetWMColormapWindows(XtDisplay(toplevel),
- XtWindow(toplevel), windows, 2);
- if (status)
- printf("error setting window colormaps\n");
- }
-
-
- static void
- usage(char *progname)
- {
- static char *help_message[] = {
- "where options include:",
- " -p[erf] show performance indicator and perf msgs",
- " -d[ebug] print debug messages",
- " -f[ps] <frames per second> set update rate, default = refresh rate",
- " -s[peed] <scan lines> set speed by # of scan lines to move in y",
- " -w[idth] <# pixels> window width in pixels (default 640)",
- " -h[eight] <# pixels> window height in pixels (default 480)",
- " -h[elp] print this usage message",
- NULL};
- char **s;
-
- printf("usage:\t%s [-options ...] [credits file]\n", progname);
- for (s= help_message; *s; s++)
- printf("%s\n", *s);
- printf("\n");
- exit(1);
- }
-
-
- void fileSelectCB(Widget, XtPointer,
- XmFileSelectionBoxCallbackStruct *cbs)
- {
- char *filename;
-
- if (!XmStringGetLtoR(cbs->value,
- XmSTRING_DEFAULT_CHARSET, &filename)) {
- printf("error\n");
- }
-
- strcpy(appResources.credFilename, filename);
- XtFree(filename);
- XtUnmanageChild(dialog);
- XtPopdown(XtParent(dialog));
- sleep(1);
- fileCB(NULL, 1);
- }
-
-
- void cancelSelectCB(Widget , XtPointer, XtPointer)
- {
- XtUnmanageChild(dialog);
- XtPopdown(XtParent(dialog));
- }
-
-
- void resetScrollCB(Widget , XtPointer, XtPointer)
- {
- restart = True;
- cpack(bgcol);
- clear();
- swapbuffers();
-
- }
-
-
- void fileCB(Widget, int itemNo)
- {
- if (itemNo == 0) {
- if (!dialog) {
- dialog = XmCreateFileSelectionDialog(toplevel, "filesb", NULL, 0);
- XtAddCallback(dialog, XmNcancelCallback, cancelSelectCB, NULL);
- XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)fileSelectCB, NULL);
- }
- XtManageChild(dialog);
- XtPopup(XtParent(dialog), XtGrabNone);
- }
- else if (itemNo == 1) {
- restart = True;
- readCreditsFile();
- grabTextBlocks(NULL, NULL, NULL);
- }
- else if (itemNo == 2)
- quitCB(NULL, NULL, NULL);
- }
-
-
-
- void
- createInterface(int *avalue, char **argv)
- {
- Arg args[20];
- int n;
-
- #ifdef SYSTYPE_SVR4
- int *argc = avalue;
- #else
- Cardinal *argc = (Cardinal *)avalue;
- #endif
-
-
- toplevel = XtAppInitialize(&app_context, "Scrollmon",
- optionDesc, XtNumber(optionDesc),
- argc, (String*)argv,
- fallback_resources,
- (ArgList)NULL, 0);
-
- XtGetApplicationResources(toplevel, (XtPointer)&appResources, Resources,
- XtNumber(Resources), (ArgList) NULL, NULL);
-
- appResources.credFilename = defaultCredFile;
- if (*argc == 2)
- appResources.credFilename = argv[1];
- else if (*argc > 2 || appResources.help)
- usage(argv[0]);
-
- n = 0;
- XtSetArg(args[n], XmNwidth, appResources.winW); n++;
- XtSetArg(args[n], XmNheight, appResources.winH); n++;
- gfxShell = XtCreatePopupShell("graphics",
- topLevelShellWidgetClass, toplevel,
- args, n);
-
- mainw = XtVaCreateManagedWidget("mainForm", xmMainWindowWidgetClass, toplevel, NULL);
- XtManageChild(mainw);
-
- XmString mbFile = XmStringCreateSimple("File");
- XmString mbOptions = XmStringCreateSimple("Options");
- menuBar = XmVaCreateSimpleMenuBar(mainw, "menuBar",
- XmVaCASCADEBUTTON, mbFile, 'F',
- XmVaCASCADEBUTTON, mbOptions, 'O',
- NULL);
- XmStringFree(mbFile);
- XmStringFree(mbOptions);
-
- XmString openfile = XmStringCreateSimple("Open");
- XmString reopenfile = XmStringCreateSimple("Re-open");
- XmString quitfile = XmStringCreateSimple("Quit");
- pulldownMenu = XmVaCreateSimplePulldownMenu(menuBar, "fileMenu", 0,
- (XtCallbackProc)fileCB,
- XmVaPUSHBUTTON, openfile, 'O', NULL, NULL,
- XmVaPUSHBUTTON, reopenfile, 'R', NULL, NULL,
- XmVaPUSHBUTTON, quitfile, 'Q', NULL, NULL,
- NULL);
- XmStringFree(openfile);
- XmStringFree(reopenfile);
- XmStringFree(quitfile);
-
- XmString miVideo = XmStringCreateSimple("Video");
- pulldownMenu = XmVaCreateSimplePulldownMenu(menuBar, "optionsMenu", 1,
- (XtCallbackProc)fileCB,
- // XmVaPUSHBUTTON, quitfile, 'V', NULL, NULL,
- NULL);
- XmStringFree(miVideo);
-
- XtManageChild(menuBar);
-
- n = 0;
- XtSetArg(args[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
- XtSetArg(args[n], XmNtopWidget, menuBar); n++;
- XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
- mainCtrl = XmCreateRowColumn(mainw, "mainCtrl", args, n);
- XtManageChild(mainCtrl);
-
- n = 0;
- XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
- #ifdef SYSTYPE_SVR4
- XtSetArg(args[n], XmNtitleString, XmStringCreateLocalized("speed")); n++;
- #else
- XtSetArg(args[n], XmNtitleString, XmStringCreate("speed", XmSTRING_DEFAULT_CHARSET)); n++;
- #endif
- XtSetArg(args[n], XmNvalue, appResources.speed); n++;
- XtSetArg(args[n], XmNshowValue, True); n++;
- XtSetArg(args[n], XmNminimum, 0); n++;
- XtSetArg(args[n], XmNmaximum, 16); n++;
- XtSetArg(args[n], XmNshowArrows, True); n++;
- speedSb = XmCreateScale(mainCtrl, "speedSb", args, n);
- XtManageChild(speedSb);
- XtAddCallback (speedSb, XmNvalueChangedCallback, updateSpeedCB, NULL);
-
- n = 0;
- XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
- rch = XmCreateRowColumn(mainCtrl, "rch", args, n);
- XtManageChild(rch);
-
- n = 0;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- chBoxes = XmCreateRowColumn(rch, "chBoxes", args, n);
- XtManageChild(chBoxes);
-
- n = 0;
- btn = XmCreateToggleButton(chBoxes, "Video-in", args, n);
- XtManageChild (btn);
-
- n = 0;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- frame = XmCreateFrame(rch, "scrFrame", args, n);
- XtManageChild(frame);
-
- n = 0;
- XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
- XtSetArg(args[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
- rcv = XmCreateRowColumn(frame, "rcv", args, n);
- XtManageChild(rcv);
-
- n = 0;
- btn = XmCreatePushButton(mainCtrl, "quitBtn", args, n);
- XtManageChild (btn);
- XtAddCallback (btn, XmNactivateCallback, quitCB, NULL);
-
-
- stopStartBtn = XmCreatePushButton(rcv, "stopStartBtn", args, n);
- XtVaSetValues(stopStartBtn,
- XmNwidth, 50,
- XmNheight, 50,
- XmNlabelType, XmPIXMAP,
- XmNentryAlignment, XmALIGNMENT_CENTER,
- XmNmarginLeft, 0,
- XmNmarginRight, 0,
- XmNrecomputeSize, False,
- NULL);
- XtManageChild(stopStartBtn);
- XtAddCallback(stopStartBtn, XmNactivateCallback, toggleMotionCB, NULL);
-
- n = 0;
- XtSetArg(args[n], XmNwidth, 50); n++;
- XtSetArg(args[n], XmNheight, 50); n++;
- XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
- XtSetArg(args[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
- XtSetArg(args[n], XmNrecomputeSize, False); n++;
- restartBtn = XmCreatePushButton(rcv, "restartBtn", args, n);
- XtManageChild(restartBtn);
- XtAddCallback(restartBtn, XmNactivateCallback, resetScrollCB, NULL);
-
- n = 0;
- XtSetArg(args[n], XmNwidth, appResources.winW); n++;
- XtSetArg(args[n], XmNheight, appResources.winH); n++;
- frame = XmCreateFrame (gfxShell, "frame", args, n);
- XtManageChild (frame);
-
- n = 0;
- XtSetArg(args[n], GlxNglxConfig, glxConfig); n++;
- glw = GlxCreateMDraw(frame, "glwidget", args, n);
- XtManageChild (glw);
-
-
- XtRealizeWidget(toplevel);
- XtPopup(gfxShell, XtGrabNone);
- installColormap(toplevel,glw);
- setPixmaps();
- }
-
-